#region

using System;
using System.Web.Mvc;
using log4net;
using xConnected.Core.Interfaces.Service;
using xConnected.Core.Model;

#endregion

namespace xConnected.Controllers
{
    public class UserController : BaseController<User>
    {
        protected IUserService UserService;

        public UserController(IUserService UserService)
        {
            base.Service = this.UserService = UserService;
        }

        public ActionResult Activate()
        {
            return View();
        }

        [HttpPost]
        public ActionResult CheckSignedIn()
        {
            ILog log = LogManager.GetLogger(GetType());
            try
            {
                var user = UserService.GetUserByUsername(User.Identity.Name);

                //if user is signed in return true
                if (user != null)
                {
                    return Json(true, JsonRequestBehavior.AllowGet);
                }
                return Json(false, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message + Environment.NewLine + "Stack: " + ex.StackTrace, ex);
                return Content("ERROR");
            }
        }
    }
}